/**  
 * Project Name:api-webhook  
 * File Name:EmailClient.java  
 * Package Name:com.example.service.webhook.api  
 * Date:2016年7月19日下午5:17:42  
 * Copyright (c) 2016, yuandong@51dojo.com All Rights Reserved.  
 *  
*/  
  
package com.example.service.webhook.business.chsi.api;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.example.service.webhook.api.MoxieClient;
import com.example.service.webhook.business.carrier.dto.BillDetail;
import com.example.service.webhook.business.carrier.dto.FamilyNetDetail;
import com.example.service.webhook.business.carrier.dto.MobileBasic;
import com.example.service.webhook.business.carrier.dto.MobileRechargeDetail;
import com.example.service.webhook.business.carrier.dto.MobileSmsDetail;
import com.example.service.webhook.business.carrier.dto.MobileVoiceCallDetail;
import com.example.service.webhook.business.carrier.dto.PackageUsageDetail;
import com.example.service.webhook.business.chsi.dto.EducationInfoDetail;
import com.example.service.webhook.business.chsi.dto.StudentInfoDetail;

import retrofit2.Call;
import retrofit2.Response;

/**  
 * ClassName:ChsiClient <br/>  
 * Function: 学信网client. <br/>  
 * Reason:   TODO ADD REASON. <br/>  
 * Date:     2016年7月19日 下午5:17:42 <br/>  
 * @author   yuandong  
 * @version    
 * @since    JDK 1.6  
 * @see        
 */
@Component
public class ChsiClient extends MoxieClient{
	
	 private ChsiApi api;
	 
	 @Autowired
	public ChsiClient(@Value("${moxie.api.baseUrl}") String apiBaseUrl,
            @Value("${moxie.api.token}") String apiToken) {
		super(apiBaseUrl, apiToken);  
		api = retrofit.create(ChsiApi.class);
	}

	private static final Logger LOGGER = LoggerFactory.getLogger(ChsiClient.class);
	
	
	
	public EducationInfoDetail getEducation(String taskId) throws IOException {
        Call<EducationInfoDetail> call = api.getEducation(taskId);
        Response<EducationInfoDetail> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("getEducation, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }
	
	public StudentInfoDetail getStudent(String taskId) throws IOException {
        Call<StudentInfoDetail> call = api.getStudent(taskId);
        Response<StudentInfoDetail> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("getStudent, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }
	
}
  
